<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Medium
  </div>
  <div>
   <h1 class="question_title">
    903. Implement Rand10() Using Rand7()
   </h1>
   <p>
    Given a function
    <code>
     rand7
    </code>
    which generates a uniform random integer in the range 1 to 7, write a function
    <code>
     rand10
    </code>
    &nbsp;which generates a uniform random integer in the range 1 to 10.
   </p>
   <p>
    Do NOT use system's
    <code>
     Math.random()
    </code>
    .
   </p>
   <ol>
   </ol>
   <p>
    &nbsp;
   </p>
   <div>
    <p>
     <strong>
      Example 1:
     </strong>
    </p>
    <pre>
<strong>Input: </strong><span id="example-input-1-1">1</span>
<strong>Output: </strong><span id="example-output-1">[7]</span>
</pre>
    <div>
     <p>
      <strong>
       Example 2:
      </strong>
     </p>
     <pre>
<strong>Input: </strong><span id="example-input-2-1">2</span>
<strong>Output: </strong><span id="example-output-2">[8,4]</span>
</pre>
     <div>
      <p>
       <strong>
        Example 3:
       </strong>
      </p>
      <pre>
<strong>Input: </strong><span id="example-input-3-1">3</span>
<strong>Output: </strong><span id="example-output-3">[8,1,10]</span>
</pre>
      <p>
       &nbsp;
      </p>
      <p>
       <strong>
        Note:
       </strong>
      </p>
      <ol>
       <li>
        <code>
         rand7
        </code>
        is predefined.
       </li>
       <li>
        Each testcase has one argument:&nbsp;
        <code>
         n
        </code>
        , the number of times that
        <code>
         rand10
        </code>
        is called.
       </li>
      </ol>
      <p>
       &nbsp;
      </p>
      <p>
       <strong>
        Follow up:
       </strong>
      </p>
      <ol>
       <li>
        What is the
        <a href="https://en.wikipedia.org/wiki/Expected_value" target="_blank">
         expected value
        </a>
        &nbsp;for the number of calls to&nbsp;
        <code>
         rand7()
        </code>
        &nbsp;function?
       </li>
       <li>
        Could you minimize the number of calls to
        <code>
         rand7()
        </code>
        ?
       </li>
      </ol>
     </div>
    </div>
   </div>
  </div>
  <div>
   <h1 class="question_title">
    903. 用 Rand7() 实现 Rand10()
   </h1>
   <p>
    已有方法&nbsp;
    <code>
     rand7
    </code>
    &nbsp;可生成 1 到 7 范围内的均匀随机整数，试写一个方法&nbsp;
    <code>
     rand10
    </code>
    &nbsp;生成 1 到 10 范围内的均匀随机整数。
   </p>
   <p>
    不要使用系统的&nbsp;
    <code>
     Math.random()
    </code>
    &nbsp;方法。
   </p>
   <ol>
   </ol>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例 1:
    </strong>
   </p>
   <pre>
<strong>输入: </strong>1
<strong>输出: </strong>[7]
</pre>
   <p>
    <strong>
     示例 2:
    </strong>
   </p>
   <pre>
<strong>输入: </strong>2
<strong>输出: </strong>[8,4]
</pre>
   <p>
    <strong>
     示例 3:
    </strong>
   </p>
   <pre>
<strong>输入: </strong>3
<strong>输出: </strong>[8,1,10]
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     提示:
    </strong>
   </p>
   <ol>
    <li>
     <code>
      rand7
     </code>
     &nbsp;已定义。
    </li>
    <li>
     传入参数:&nbsp;
     <code>
      n
     </code>
     &nbsp;表示&nbsp;
     <code>
      rand10
     </code>
     &nbsp;的调用次数。
    </li>
   </ol>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     进阶:
    </strong>
   </p>
   <ol>
    <li>
     <code>
      rand7()
     </code>
     调用次数的&nbsp;
     <a href="https://en.wikipedia.org/wiki/Expected_value" target="_blank">
      期望值
     </a>
     &nbsp;是多少&nbsp;?
    </li>
    <li>
     你能否尽量少调用
     <code>
      rand7()
     </code>
     ?
    </li>
   </ol>
  </div>
 </body>
</html>